package com.stateMode;

import java.util.Random;

/**
 * 可以抽奖状态
 */
public class CanRaffleState extends State{

    RaffleActivity activity ;

    //构造
    public CanRaffleState(RaffleActivity activity) {
        this.activity = activity;
    }

    @Override
    public void deductMoney() {
        System.out.println("您已经扣过积分了 不用重新扣款 ... ");
    }

    @Override
    public boolean raffle() {
        System.out.println("正在抽奖请稍等 ... ");
        //抽奖的中奖率只有10%
        Random r = new Random();
        int num = r.nextInt(10);
        if (num == 0 ){
            //中奖了 让活动状态变为颁奖状态
            activity.setState(activity.getDispenseState());
            return true;
        }else {
            System.out.println("很遗憾，请下次再来 ... ");
            //没有中奖，变为不可抽奖状态
            activity.setState(activity.noRaffleState);
            return false;
        }
    }

    @Override
    public void dispensePrise() {
        System.out.println("没中奖,不能发放奖品  ... ");
    }
}
